package org.hackystat.projecttrajectory;

import java.util.List;
import org.hackystat.project.PersonalProjectSummaryFactory;
import org.hackystat.project.ProjectException;
import org.hackystat.project.ProjectSummary;
//import org.hackystat.project.explorer.ProjectExplorer;
import org.hackystat.sensorbase.resource.projects.jaxb.Project;

/**
 * Represents the size, effort and duration trajectory for a project.
 * 
 * @author Cam Moore
 * 
 */
public class ProjectTrajectory {

//  private ProjectExplorer explorer;
//  private Project project;
  private List<ProjectSummary> summaries;
  
  /**
   * Constructs a ProjectTrajectory from the given Project.
   * 
   * @param project a Project.
   * @throws ProjectException if the DailyProjectData service doesn't talk to the
   * same sensorbase.
   */
  public ProjectTrajectory(Project project) throws ProjectException {
//    this.project = project;
//    explorer = new ProjectExplorer();
    summaries = PersonalProjectSummaryFactory.getInstance().getSummaries(project);
  }
  
  /**
   * @return A comma separated string of the Project's trajectory.
   */
  public String toCSV() {
    StringBuffer buff = new StringBuffer(32);
    ProjectSummary summary;
    buff.append("Date,LOC,Effort\n");
    for (int i = 0; i < summaries.size(); i++) {
      summary = summaries.get(i);
      buff.append(summary.getDate());
      buff.append(',');
      buff.append(summary.getTotalLines());
      buff.append(',');
      buff.append(summary.getTotalEffort());
      buff.append('\n');
    }
    return buff.toString();
  }
  
  /**
   * Command line interface.
   * @param args a String[].
   * @throws ProjectException if there is a problem.
   */
  public static void main(String args[]) throws ProjectException {
    PersonalProjectSummaryFactory factory = PersonalProjectSummaryFactory.getInstance();
    List<Project> projects = factory.getProjects();
    ProjectTrajectory trajectory = new ProjectTrajectory(projects.get(0));
    System.out.println(projects.get(0).getName() + "'s trajectory:");
    System.out.println(trajectory.toCSV());
  }
}
